﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="clr-namespace:Gaiocorp.SLMapViewer"
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:Res="clr-namespace:Gaiocorp.SLMapViewer.Resources"
    xmlns:local="clr-namespace:Gaiocorp.SLMapViewer"
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc1="http://schemas.openxmlformats.org/markup-compatibility/2006" mc1:Ignorable="d" x:Class="Gaiocorp.SLMapViewer.MapControl" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">

    <UserControl.Resources>
        <Res:ApplicationStrings x:Key="ApplicationStrings"/>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White" Width="500" Height="500"
            MouseLeftButtonDown="MapImg_MouseLeftButtonDown"
            MouseLeftButtonUp="MapImg_MouseLeftButtonUp" 
            MouseMove="MapImg_MouseMove"
            MouseRightButtonDown="MapImg_MouseRightButtonDown"
            MouseLeave="MapImg_MouseLeave"
            LostMouseCapture="MapImg_LostMouseCapture">
        <Border BorderBrush="Black" BorderThickness="1">
        <Canvas x:Name="cnvMap" Opacity="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
            <Image  x:Name="MapImg"
                Canvas.Left="0"
                Canvas.Top="0">
                <Image.Resources>
                    <Storyboard x:Name="myStoryboard">
                        <DoubleAnimation Storyboard.TargetName="MapImg" Storyboard.TargetProperty="Opacity" From="0.0" To="1.0" Duration="0:0:1" AutoReverse="False" />
                    </Storyboard>
                </Image.Resources>
            </Image>
            <Rectangle
                    x:Name="rectMap"
                    Canvas.Top="0"
                    Canvas.Left="0"
                    Stroke="Black"
                    StrokeThickness="2"
                    RadiusX = "3"
                    RadiusY = "3"/>
            <!--
                Map Toolbar 
            -->
            <local:MapToolBar x:Name="mapTools" />
            <!-- 
                The rectangle to be displayed when clicking and dragging on the map 
            -->
            <Canvas x:Name="cnvRectCanvas"  
                        Background="White" d:IsHidden="True">
                <Rectangle
                        x:Name="dynrectangle" Visibility="Collapsed"
                        Canvas.Top="-50"
                        Width="50"
                        Height="50"
                        Fill="Yellow"
                        Opacity="0.7"
                        Stroke="Red"
                        StrokeThickness="2"/>
            </Canvas>
            <!-- 
                The lines to use for the measure tool 
            -->
            <Polyline x:Name="UserMeasurePolyLine" Stroke="Blue" StrokeThickness="3"/>
            <Line x:Name="UserMeasureLine" Stroke="Blue" StrokeThickness="3"/>
            <Border x:Name="brdMeasureToolTip" BorderBrush="Black" CornerRadius="5" Background="WhiteSmoke" Visibility="Collapsed" Canvas.Top="30" Canvas.Left="2" Width="160" Height="65">
                <Grid x:Name="gridMeasureToolTip" ShowGridLines="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="20"></RowDefinition>
                        <RowDefinition Height="20"></RowDefinition>
                         <RowDefinition Height="20"></RowDefinition>
                        </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100"></ColumnDefinition>
                            <ColumnDefinition Width="50"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                        <TextBlock Text="Segment Length:" HorizontalAlignment="Left"></TextBlock>
                        <TextBlock Text="Total Length:" Grid.Row="1" Grid.Column="0"  HorizontalAlignment="Left" />
                        <TextBlock x:Name="txbMeasLength" Text="" Grid.Row="0" Grid.Column="1" />
                        <TextBlock x:Name="txbTotalLength" Text="" Grid.Row="1" Grid.Column="1" />
                        <TextBlock Text="Right click to exit measure mode" Grid.Row="2" Grid.ColumnSpan="2" />
                    </Grid>
            </Border>
                <!-- Hidden fields -->
            <Grid x:Name="gridDebug" ShowGridLines="true" Width="400" Canvas.Top="100">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <TextBox x:Name="stxtXMin" Grid.Row="0" Grid.Column="0" Text=""/>
                <TextBox x:Name="stxtXMax" Grid.Row="0" Grid.Column="1" Text=""/>
                <TextBox x:Name="stxtYMin" Grid.Row="0" Grid.Column="2" Text=""/>
                <TextBox x:Name="stxtYMax" Grid.Row="0" Grid.Column="3" Text=""/>
                <TextBox x:Name="stxtTest1" Grid.Row="1" Grid.Column="0" Text="{Binding Test, Source={StaticResource ApplicationStrings}}" Canvas.Top="100"/>
                <TextBox x:Name="stxtActiveTool" Text="NONE" Grid.Row="1" Grid.Column="1"/>
                <TextBox x:Name="stxtActiveLayer" Text="" Grid.Row="1" Grid.Column="2"/>
                <TextBox x:Name="stxtActiveLayerName" Text="" Grid.Row="1" Grid.Column="3"/>
                <TextBox x:Name="stxtRequest" Text="" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" TextChanged="stxtRequest_TextChanged"/>
                <TextBox x:Name="stxtResponse" Text="" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" Visibility="Visible" Canvas.Top="60" TextWrapping="Wrap"/>
                <TextBox x:Name="stxtHasSelection" Text="" Grid.Row="4" Grid.Column="0"/>
            </Grid>
            <!-- 
                Status Grid 
                -->
            <Border x:Name="brdStatus" Background="Beige" Opacity="1" BorderBrush="Black" Height="20" BorderThickness="2" Visibility="Visible">
                <Grid x:Name="gridStatus" Background="Beige" Opacity="1" ShowGridLines="False">
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock x:Name="txbLayerInfo" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Top"  Text="" Foreground="Black" />
                    <TextBlock x:Name="txbScale" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Text="{Binding Scale, Source={StaticResource ApplicationStrings}}" Foreground="Black" />
                    <TextBox x:Name="txtScale" Width="250"
                            Opacity="1" Background="White" 
                            Grid.Column="2" Grid.Row="0" 
                            Padding="0,0,0,0"
                            HorizontalAlignment="Left" VerticalAlignment="Top" 
                            Text="" Foreground="Black" KeyDown="txtScale_KeyDown"
                            >
                    </TextBox>
                    <TextBlock x:Name="stxtStatusBar" Text="" HorizontalAlignment="Right" TextAlignment="Right" Grid.Column="3" Grid.Row="0" />
                </Grid>
            </Border>
            <!-- 
                Query By Attributes 
            -->
            <Border x:Name="brdQuery" Background="Silver" Opacity="1" BorderBrush="Black" BorderThickness="2" Visibility="Collapsed">
                <ScrollViewer x:Name="Sv0" 
                                        Margin="0,0,0,0" 
                                        VerticalScrollBarVisibility="Auto" 
                                        HorizontalScrollBarVisibility="Auto"
                                        >
                    <Grid x:Name="gridQuery" Background="Silver" ShowGridLines="False" >
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition Width="200"/>

                        </Grid.ColumnDefinitions>
                        <Rectangle x:Name="RectQTitle" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" Fill="Blue" Height="20"/>
                        <TextBlock x:Name="txbQTitle" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" Text="{Binding QueryByAttrsTitle, Source={StaticResource ApplicationStrings}}" Foreground="White"  Margin="5"/>
                        <TextBlock x:Name="txbQLayers" Grid.Row="1" Grid.Column="0" Text="{Binding LayerCboLabel, Source={StaticResource ApplicationStrings}}" Foreground="Black"  Margin="5"/>
                        <ComboBox x:Name="cboLayers" 
                            Grid.Row="1" Grid.Column="1"
                            Grid.ColumnSpan="1" 
                            SelectionChanged="cboLayers_SelectionChanged"
                            Width="150" Margin="5"/>
                        <TextBlock x:Name="txbQAttrs" Grid.Row="2" Grid.Column="0" Text="{Binding AttributesLabel, Source={StaticResource ApplicationStrings}}" Foreground="Black"  Margin="5"/>
                        <ListBox x:Name="lsAttrs" 
                            Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="1" 
                            Padding="5"
                            SelectionChanged="lsAttrs_SelectionChanged"
                            MouseLeftButtonUp="lsAttrs_MouseLeftButtonUp"/>
                        <TextBlock x:Name="txbOps" Grid.Row="3" Grid.Column="0" Text="{Binding OperatorsLabel, Source={StaticResource ApplicationStrings}}" Foreground="Black"  Margin="5"/>
                        <ComboBox x:Name="cboOps" 
                            Grid.Row="3" Grid.Column="1"
                            Grid.ColumnSpan="1"
                            SelectionChanged="cboOps_SelectionChanged"
                            Width="150" Margin="5">
                            <ComboBoxItem Content="="/>
                            <ComboBoxItem Content="&lt;&gt;"/>
                            <ComboBoxItem Content="&gt;"/>
                            <ComboBoxItem Content="&lt;"/>
                            <ComboBoxItem Content="&gt;="/>
                            <ComboBoxItem Content="&lt;="/>
                            <ComboBoxItem Content="LIKE"/>
                            <ComboBoxItem Content="AND"/>
                            <ComboBoxItem Content="OR"/>
                            <ComboBoxItem Content="NOT"/>
                            <ComboBoxItem Content="()"/>
                        </ComboBox>
                        <TextBlock x:Name="txbQSelect" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Left" Text="" Foreground="Black"  Margin="5"/>
                        <TextBlock x:Name="txbQValue" Grid.Row="5" Grid.Column="0" Text="{Binding ValueLabel, Source={StaticResource ApplicationStrings}}" Foreground="Black"  Margin="5"/>
                        <TextBox x:Name="txtQuery" 
                            Text="" TextWrapping="Wrap" 
                            Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="3" Height="100" Margin="5" />
                        <Button x:Name="btnCloseQuery" 
                            Content="{Binding Close, Source={StaticResource ApplicationStrings}}" 
                            Width="70" 
                            Margin="5" 
                            Grid.Row="6" 
                            Grid.Column="0"
                            Grid.ColumnSpan="4"
                            IsEnabled="True"
                            HorizontalAlignment="Left"
                            Click="btnCloseQuery_Click"/>
                        <Button x:Name="btnDoQuery" 
                            Content="{Binding DoQuery, Source={StaticResource ApplicationStrings}}" 
                            Width="70" 
                            Margin="5" 
                            Grid.Row="6" 
                            Grid.Column="1"
                            Grid.ColumnSpan="1"
                            IsEnabled="True"
                            HorizontalAlignment="Right"
                            Click="btnDoQuery_Click"/>
                    </Grid>

                </ScrollViewer>
            </Border>

            <!-- 
                Results window 
            -->

            <Border x:Name="brdResults" Background="Beige" Opacity="1" BorderBrush="Black" 
                    Height="Auto" Width="Auto" BorderThickness="2" Visibility="Collapsed">
                <Grid x:Name="gridResults" Background="White" Width="450">
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="60"/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Rectangle x:Name="RectTitle2" Grid.Row="0" Grid.ColumnSpan="3" Fill="Blue" Height="20"/>
                    <TextBlock x:Name="ResultsTitle" Grid.Row="0" Grid.ColumnSpan="2" Text="{Binding SearchResultsTitle, Source={StaticResource ApplicationStrings}}" Foreground="White"  Margin="5"/>
                    <Button x:Name="btnCloseResult" 
                                Grid.Row="3"
                                Grid.Column="3" 
                                Width="80" Margin="3"
                                Content="{Binding Close, Source={StaticResource ApplicationStrings}}"
                                Click="xbtnCloseResults_Click"/>
                    <Button x:Name="btnShowExtDetails" Grid.Row="1" HorizontalAlignment="Stretch"  Grid.Column="0" Width="130" Height="40"
                                    Click="btnShowExtDetails_Click"
                                   ToolTipService.ToolTip="{Binding ZoomToSelected, Source={StaticResource ApplicationStrings}}">
                            <StackPanel Orientation="Horizontal">
                                <Image  x:Name="imgShowExtDetails" 
                                    Source="Images/list.png" 
                                    Margin="2,0,2,2" 
                                    Width="20" Height="20"
                                    ToolTipService.ToolTip="{Binding ShowDetailsBtn, Source={StaticResource ApplicationStrings}}"/>
                                <TextBlock Text="{Binding ShowDetailsBtn, Source={StaticResource ApplicationStrings}}" Width="100" TextWrapping="Wrap"></TextBlock>
                            </StackPanel>
                        </Button>
                        <Button x:Name="btnZoomToResult" Grid.Row="1" Grid.Column="1"  Width="130" Height="40"
                                    Click="btnZoomToResult_Click" HorizontalAlignment="Left"
                                    ToolTipService.ToolTip="{Binding ZoomToSelected, Source={StaticResource ApplicationStrings}}">
                            <StackPanel Orientation="Horizontal">
                                <Image  x:Name="imgZoomToResult" 
                                        Source="Images/internet_networking.png" 
                                        Margin="2,2,2,2" 
                                        Width="20" Height="20"/>
                                <TextBlock Text="{Binding ZoomToSelected, Source={StaticResource ApplicationStrings}}" Width="100" TextWrapping="Wrap"></TextBlock>
                                
                            </StackPanel>
                        </Button>
                        <ScrollViewer x:Name="Sv1" 
                                    Height="200" 
                                    VerticalScrollBarVisibility="Auto" 
                                    HorizontalScrollBarVisibility="Auto"
                                    Grid.Column="0" Grid.Row="2"
                                    Grid.ColumnSpan="3">
                        <data:DataGrid x:Name="gridDataResults"
                                Grid.Column="0"  
                                Grid.Row="2"
                                SelectedIndex="-1"  
                                AutoGenerateColumns="False" 
                                SelectionMode="Single" 
                                IsReadOnly="True"
                                SelectionChanged="gridDataResults_SelectionChanged" />
                    </ScrollViewer>
                    <TextBlock x:Name="ResultsCount" Grid.Row="3" Grid.ColumnSpan="2" Text="" Foreground="Black"  Margin="5"/>
                </Grid>
            </Border>
            <toolkit:Expander ExpandDirection="Down" Background="Black" Foreground="White" Width="300" Height="30"
                                  Name="expLegend"
                                  Expanded="expLegend_Expanded" Collapsed="expLegend_Collapsed">
                    <toolkit:Expander.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Legend, Source={StaticResource ApplicationStrings}}" RenderTransformOrigin="0.7,0.2">
                                <TextBlock.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform/>
                                    <SkewTransform/>
                                    <RotateTransform Angle="0"/>
                                    <TranslateTransform/>
                                </TransformGroup>
                                </TextBlock.RenderTransform>
                            </TextBlock>
                        </DataTemplate>
                    </toolkit:Expander.HeaderTemplate>
                    <toolkit:Expander.Content>
                        <local:LegendControl x:Name="legend" TitleColor="White" BackgroundOpacity="1.0" BackroundColor="Black" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                    </toolkit:Expander.Content>

                </toolkit:Expander>
            </Canvas>
        </Border>
       
        <!-- 
                Wait window 
        -->
        <Border x:Name="brdWait" Background="Beige" Opacity="0.8" BorderBrush="Black"  BorderThickness="4" Width="220" Height="110" Visibility="Collapsed">
            <Canvas x:Name="WaitBanner" Background="Beige" Visibility="Visible">
                <Image x:Name="WaitImg" 
                            Source="Images/reload_48.png" 
                            Canvas.Top="26" Canvas.Left="10"/>
                <TextBox x:Name="stxtPleaseWait" Text="{Binding Path=PleaseWait, Source={StaticResource ApplicationStrings}}" Canvas.Top="50" Canvas.Left="60" Background="Beige" Visibility="Visible" BorderThickness="0" />
            </Canvas>
        </Border>
        <!-- 
                Print Dialog 
        -->
        <Border x:Name="brdPrint" Opacity="1" BorderBrush="Black" BorderThickness="2" Visibility="Collapsed" Height="169" Margin="100,150,69,150" Width="320">
            <Grid x:Name="gridPrint" Background="White" Opacity="1" ShowGridLines="false" Width="317" Height="169">
                <Grid.RowDefinitions>
                    <RowDefinition Height="34*" />
                    <RowDefinition Height="24*" />
                    <RowDefinition Height="37*" />
                    <RowDefinition Height="28*" />
                    <RowDefinition Height="46*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="115*" />
                    <ColumnDefinition Width="164*" />
                    <ColumnDefinition Width="38*" />
                </Grid.ColumnDefinitions>
                <Rectangle x:Name="RectPrintTitle" RadiusX="5" RadiusY="5" Grid.ColumnSpan="3" Fill="Black" Height="20" Margin="2"/>
                <TextBlock x:Name="txbPrintWinTitle" Grid.ColumnSpan="3" Text="{Binding PrintOptionsTitle, Source={StaticResource ApplicationStrings}}" Foreground="White"  Margin="8"/>
                <TextBlock x:Name="txbPrintTitle" Grid.Column="0" Grid.Row="1" Width="80" HorizontalAlignment="Right" VerticalAlignment="Top"  Text="{Binding MapTitle, Source={StaticResource ApplicationStrings}}" Foreground="Black" Margin="2 2 2 2" />
                <TextBox x:Name="txtPrintTitle" 
                            Opacity="1" Background="White" 
                            Grid.Column="1" Grid.Row="1" 
                            Width="180" 
                            HorizontalAlignment="Left" VerticalAlignment="Top" 
                            Padding="0 0 0 0" 
                            Text="" Foreground="Black" Grid.ColumnSpan="2" />
                <TextBlock x:Name="txbPrintSize" Grid.Column="0" Grid.Row="2" Width="100" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  Text="{Binding PaperSize, Source={StaticResource ApplicationStrings}}" Foreground="Black" Margin="0,10,0,0" />
                <ComboBox x:Name="cboPaperSizes" 
                            Grid.Row="2" HorizontalAlignment="Stretch"
                            Width="150" Margin="26,2,26,0" SelectedIndex="0" Grid.Column="1" Height="25" Grid.ColumnSpan="2">
                    <ComboBoxItem Content="A4 LandScape" Tag="A4L"/>
                    <ComboBoxItem Content="A4 Portait" Tag="A4P"/>
                    <ComboBoxItem Content="A3 LandScape" Tag="A3L"/>
                    <ComboBoxItem Content="A3 Portait" Tag="A3P"/>
                </ComboBox>
                <TextBlock x:Name="txbPrintScale" Grid.Column="0" Grid.Row="3" Width="90" HorizontalAlignment="Right" VerticalAlignment="Top"  Text="{Binding Scale, Source={StaticResource ApplicationStrings}}" Foreground="Black" Margin="2 2 2 2"/>
                <TextBox x:Name="txtPrintScale" 
                            Opacity="1" Background="White" 
                            Grid.Column="1" Grid.Row="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                            Padding="0 0 0 0" 
                            Text="" Foreground="Black" Margin="24,0" Height="20" Grid.ColumnSpan="2">
                </TextBox>
                <Button x:Name="btnPrint" 
                        Content="{Binding Print, Source={StaticResource ApplicationStrings}}" 
                        Width="70" 
                        Margin="5,5,5,5" 
                        Grid.Row="4" 
                        Grid.Column="0"
                        IsEnabled="True"
                        HorizontalAlignment="Left"
                        Click="btnPrint_Click" Height="25" />
                <Button x:Name="btnPrintClose" 
                        Content="{Binding Close, Source={StaticResource ApplicationStrings}}" 
                        Width="70" 
                        Margin="0,5,5,5" 
                        Grid.Row="4" 
                        Grid.Column="1"
                        IsEnabled="True"
                        HorizontalAlignment="Right"
                        Click="btnPrintClose_Click" Height="25" Grid.ColumnSpan="2" />
            </Grid>
        </Border>
        <!-- 
                Error window 
        -->
        <local:ErrowWindow x:Name="ErrorDialog" Visibility="Collapsed" Canvas.Top="10" Canvas.Left="30"/>
       
    </Grid>
</UserControl>
